package com.xjtu.platform.respondent.respond;


import com.xjtu.platform.common.CommonService;
import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import com.xjtu.platform.common.dao.CommonDao;
import com.xjtu.platform.common.model.User.User;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/respondent")
public class RespondAPI {

    @Resource
    private RespondService respondService;

    @Resource
    private CommonService commonService;


    @RequestMapping(value = "/respond",method = RequestMethod.GET)
    public Result respondList(@RequestHeader("Token") String token){
        CurrentUser currentUser = TokenUtils.getUserInfo(token,commonService);
        Map<String,Object> page = respondService.getRespondList(currentUser);
        return Result.success(page);
    }


    @PostMapping("/updateinfo")
    public Result updateinfo(@RequestBody RespondDto dto){
        try{
            respondService.updateInfo(dto);
            return Result.success();
        }catch(Exception e) {
            e.printStackTrace();
        }
        return Result.fail(400,"系统错误！");
    }
}

